package com.taldh.algorithm.array;

import org.junit.Assert;
import org.junit.Test;

public class FindMaxConsecutiveOnes {

    public int findMaxConsecutiveOnes(int[] nums) {
        int ans = 0;
        int count = 0;
        for (int num : nums) {
            if (num == 1) {
                ans = Math.max(ans, ++count);
            } else {
                count = 0;
            }
        }
        return ans;
    }

    @Test
    public void test() {
        Assert.assertEquals(3, findMaxConsecutiveOnes(new int[]{1,1,0,1,1,1}));
    }

    @Test
    public void test1() {
        Assert.assertEquals(2, findMaxConsecutiveOnes(new int[]{1,0,1,1,0,1}));
    }
}